const express = require('express')
const validate = require('express-validation')
const _ = require('lodash')
const moment = require('moment')
const managerController = require('../controller/managerController')
const tokenChecker = require('../util/tokenChecker')

const managerRouter = express.Router()

managerRouter.post('/login', async (req, res, next) => {
  const { managerId, password } = req.body
  try {
    const result = await managerController.login({ managerId, password })
    res.json({ status: 200, msg: '登录成功', data: { result } })
  } catch (e) {
    next(e)
  }
})
managerRouter.post('/add', async (req, res, next) => {
  const { managerId, password, power } = req.body
  try {
    const result = await managerController.addMember({ managerId, password, power })
    res.json({ status: 200, msg: '登录成功', data: { result } })
  } catch (e) {
    next(e)
  }
})
managerRouter.get('/info', tokenChecker, async (req, res, next) => {
  const managerId = req.uuId
  try {
    const info = await managerController.getManagerByKey({ managerId })
    res.json({
      status: 200,
      msg: '获取详情成功',
      data: {
        result: info
      }
    })
  } catch (e) {
    next(e)
  }
})
module.exports = managerRouter
